package com.appcenter.message.controller;

import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.appcenter.message.input.*;
import com.appcenter.message.input.externalapi.ReadMsgInput;
import com.appcenter.message.input.externalapi.SendMsgInput;
import com.appcenter.message.output.externalapi.ReadMsgOutput;
import com.appcenter.message.service.MessagesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzmessagecenterservice/Message")
@Api(value="消息操作API",description = "消息操作API")
public class MessageCenterController {
    @Autowired
    MessagesService msgService;

    @ApiOperation(value = "发送消息", notes = "发送消息",produces = "application/json")
    @PostMapping("/sendMessage")
    public ResponseEntity<JsonResult> sendMessage(@RequestBody SendMsgInput input) throws Exception {

        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.SendMessage(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "补发消息", notes = "补发消息",produces = "application/json")
    @PostMapping("/replenish")
    public ResponseEntity<JsonResult> replenish(@RequestBody ReplenishInput input) throws Exception {

        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.Replenish(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "读取消息", notes = "读取消息",produces = "application/json")
    @PostMapping("/readMessage")
    public ResponseEntity<JsonResult> readMessage(@RequestBody ReadMsgInput input) throws Exception {

        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.ReadMessage(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);

    }


    @ApiOperation(value = "读取消息个数", notes = "读取消息个数",produces = "application/json")
    @PostMapping("/getUnreadMessageCount")
    public ResponseEntity<JsonResult> getUnreadMessageCount(@RequestBody GetUnreadMessageCountInput input) throws Exception {

        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.GetUnreadMessageCount(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);

    }


    @ApiOperation(value = "查询消息信息", notes = "查询消息信息",produces = "application/json")
    @PostMapping("/SearchMessageList")
    public ResponseEntity<JsonResult> searchMessageList(@RequestBody SearchMessageListInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.SearchMessageList(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);


    }


    @ApiOperation(value = "加载消息信息", notes = "加载消息信息",produces = "application/json")
    @PostMapping("/LoadMessageListPage")
    public ResponseEntity<JsonResult> loadManageMessageListPage(@RequestBody LoadMessageListPageInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.LoadMessageListPage(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);

    }


    @ApiOperation(value = "查询平台消息信息", notes = "查询平台消息信息",produces = "application/json")
    @PostMapping("/SearchManageMessageList")
    public ResponseEntity<JsonResult> SearchManageMessageList(@RequestBody SearchManageMessageListInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.SearchManageMessageList(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);


    }



    @ApiOperation(value = "加载平台消息信息", notes = "加载平台消息信息",produces = "application/json")
    @PostMapping("/LoadManageMessageListPage")
    public ResponseEntity<JsonResult> LoadManageMessageListPage(@RequestBody LoadManageMessageListPageInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(msgService.LoadManageMessageListPage(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);


    }




}
